const db = require('../config/db')
const userSysModel = '../schema/sys_user'

const Mall = db.MallSequelize    //实例化数据库
const sys_user = Mall.import(userSysModel)   //实例化user

// 登陆
const login = async function(data) {
  const result = await sys_user.findOne({
    where: {
      name: data.name
    }
  })
  return result
}
// 获取用户信息

const getInfo = async (data) => {
    const result = await sys_user.findOne({
      where: {
        name: data
      }
    })
    const obj = {
      username: result.name,
      roles: [result.role]
    }
    return obj
}
// 注册
const register = async function(data) {
  const result = await sys_user.create({
    name: data.name,
    password: data.password
  })
  return true
}

module.exports = {
  login,
  register,
  getInfo
}